package com.haoran.dwz.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.haoran.dwz.service.DwzService;
import com.haoran.dwz.service.impl.DwzServiceAsyncHttpClientImpl;
import com.ning.http.client.AsyncHttpClient;
import com.ning.http.client.AsyncHttpClientConfig;

@Configuration
public class AsynHttpClientConfig {

	@Value("${http.timeout.connect:3000}")
	private int connectTimeOut;

	@Value("${http.timeout.request:3000}")
	private int requestTimeout;

	@Value("${http.timeout.read:3000}")
	private int readTimeout;

	@Bean
	public AsyncHttpClient asyncHttpClient() {

		AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
		builder.setConnectTimeout(connectTimeOut);
		builder.setReadTimeout(readTimeout);
		builder.setRequestTimeout(requestTimeout);
		return new AsyncHttpClient(builder.build());
	}

	@Bean
	public DwzService dwzService() {
		return new DwzServiceAsyncHttpClientImpl();
	}
}
